<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
	<legend>{$page_name}</legend>
</fieldset>
<form action="{:url(request()->action())}" method="post">
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
	<ul class="layui-tab-title">
		{volist name="type_group" id="vg" key="k"}
			<li class="{eq name='k' value='1'} layui-this {/eq}">{$vg.name}</li>
		{/volist}
	</ul>
	<div class="layui-tab-content">
		{volist name="type_group" id="vg" key="k"}
			<div class="layui-tab-item {eq name='k' value='1'} layui-show {/eq}">

				<div class="layui-form">
					{eq name='k' value='1'}
						<div class="layui-form-item">
							<label class="layui-form-label">栏目</label>
							<div class="layui-input-block" style="max-width: 400px;">
								<select name="cat_id" lay-filter="cat_id">
								{volist name="cat_lists" id="vo"}
									<option value="{$vo.id}" {if $vo.id == $info.cat_id} selected {/if} {if $info.table_id != $vo.table_id} disabled {/if}>{$vo.name|raw}</option>
								{/volist}
								</select>
							</div>
						</div>
					{/eq}

					{volist name="field_lists[$vg['id']]" id="vo"}
						{switch $vo.type}
							{case input|email|mobile|price|number|time|date|datetime }

								<div class="layui-form-item">
									<label class="layui-form-label">{$vo.cname}</label>
									<div class="layui-input-inline" style="width: 400px;">
										<input type="text" class="layui-input wy-type-{$vo.type}" name="{$vo.field_name}" value="{$info[$vo['field_name']]}" lay-verify="{if $vo.is_required==1}required|{/if}ver_{$vo.type}" placeholder="请输入{$vo.cname}">
									</div>
									<div class="layui-form-mid layui-word-aux">请输入{$vo.cname}</div>
								</div>
							{/case}
							{case textarea }
								<div class="layui-form-item layui-form-text">
									<label class="layui-form-label">{$vo.cname}</label>
									<div class="layui-input-inline" style="width: 400px;">
										<textarea name="{$vo.field_name}" class="layui-textarea wy-type-{$vo.type}" lay-verify="{if $vo.is_required==1}required|{/if}ver_{$vo.type}" placeholder="请输入{$vo.cname}">{$info[$vo['field_name']]}</textarea>
									</div>
								</div>
							{/case}
							{case basics|simple|complete }
							<div class="layui-form-pane">
								<div class="layui-form-item layui-form-text">
									<label class="layui-form-label">{$vo.cname}</label>
									<div class="layui-input-block" style="border: 1px solid #CCCCCC;">
										<textarea name="{$vo.field_name}" class="layui-textarea wy-type-{$vo.type}" id="wy_edit_{$vo.field_name}" lay-verify="{if $vo.is_required==1}required|{/if}ver_{$vo.type}" placeholder="请输入{$vo.cname}" style="width: 100%;height:400px;" >{$info[$vo['field_name']]}</textarea>
									</div>
								</div>
							</div>

							{/case}
							{case select }
								{php}$loading_num++;{/php}
								<div class="layui-form-item ajax_select_config" name="{$vo.field_name}" field_type="{$vo.type}" attr_type="{$vo.attr_type}" val="{$info[$vo['field_name']]}">
									<label class="layui-form-label">{$vo.cname}</label>
								</div>
							{/case}
							{case radio|checkbox }
								{php}$loading_num++;{/php}
								<div class="layui-form-item ajax_checkbox_config" name="{$vo.field_name}" field_type="{$vo.type}" attr_type="{$vo.attr_type}" val="{$info[$vo['field_name']]}">
									<label class="layui-form-label">{$vo.cname}</label>
								</div>
							{/case}
							{default /}
						{/switch}

					{/volist}

					{eq name='k' value='1'}
						<div class="layui-form-item">
							<label class="layui-form-label">展示顺序</label>
							<div class="layui-input-inline" style="width: 400px;">
								<input type="number" class="layui-input" name="sort" value="{$info.sort}" min="0" lay-verify="" placeholder="">
							</div>
							<div class="layui-form-mid layui-word-aux">展示顺序，数值越大越靠前</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label">发布时间</label>
							<!-- <div class="layui-input-inline"> -->
							<div class="layui-input-inline" style="width: 400px;">
								<input type="text" class="layui-input wy-datetime" name="push_date" value="{$info.push_date}" placeholder="发布时间">
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label">启用状态</label>
							<div class="layui-input-block">
								<input type="radio" name="status" value="1" title="开启" {if $info.status == 1} checked {/if}>
								<input type="radio" name="status" value="0" title="关闭" {if $info.status == 0} checked {/if}>
							</div>
						</div>
					{/eq}
				</div>
			</div>
		{/volist}
	</div>
</div>
<div class="layui-form">
	<div class="layui-form-item">
		<div class="layui-input-block">
			<input name="id" type="hidden" value="{$info.id}">
			<input name="table_id" type="hidden" value="{$info.table_id}">
			<button class="layui-btn" type="button"
					lay-submit
					lay-filter="wy-lists"
				>确认提交</button>
			<button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
		</div>
	</div>

</div>
</form>
<script>
var Kind_upload_json = "{:url('editor/kind_upload_json')}";
var Kind_file_manager_json = "{:url('editor/kind_file_manager_json')}";
</script>

<link href="{$public}kind_editor/themes/default/default.css{$version}" rel="stylesheet">
<script src="{$public}kind_editor/kindeditor-all.js{$version}"></script>
<script src="{$public}kind_editor/kind_editor_config.js{$version}"></script>

<script>
layui.use(['form','layer','element'], function(){
	var $		= layui.jquery,
		element = layui.element,
		$parent	= parent.layui.jquery,
		$top	= parent.parent.layui.jquery,
		layer	= layui.layer,
		parent_layer	= parent.layui.layer,
		top_layer		= parent.parent.layui.layer,
		form	= layui.form;

	form.on('submit(wy-lists)',function(data){

		var _this = $(this);
		_this.prop("disabled",true);
		var layer_tip = layer.load(1,{shade: [0.5,'#000']});
		var _form_action = _this.parents('form');
		$.post(
			_form_action.attr('action'),
			_form_action.serialize(),
			function(ret_data){
				_this.prop("disabled",false);
				if(ret_data['code'] == 1){
					layer.msg(
						ret_data.msg,
						{icon: 1,time: 2000},
						function(){
							// 刷新列表
							var bdoy1 = $parent.find("iframe#tree_id_content_index")[0].contentWindow.$.find("iframe#tree_id_{$wy_layui_id}")[0].contentWindow;
							bdoy1.layui.table.reload('wy_table_lists');
							parent_layer.closeAll();
						}
					);
				}else{
					layer.msg(ret_data.msg,{icon: 2});
					layer.close(layer_tip);
				}
			},
			'JSON'
		);
	});


	var layer_loading = layer.load(1,{shade: [0.5,'#000']});
	var loading_num = {$loading_num};
	function close_loading(){
		if(loading_num == 0){
			layer.close(layer_loading);
		}
	}
	close_loading();
	$('.ajax_checkbox_config').each(function(){
		var _this = $(this);
		var name = _this.attr('name');
		var field_type = _this.attr('field_type');
		var attr_type = _this.attr('attr_type');
		var val = _this.attr('val');
		$.post("{:url('Contentajax/ajax_select_config')}",{field_type:field_type,attr_type:attr_type,val:val},function(data){
			if(data.code != 1){
				layer.msg(data.msg,{icon:0});
				return false;
			}
			if(data.data){
				if(data.data.length == 0){
					return false;
				}

				var _html = '<div class="layui-input-block">';
				var config_area = data.data;
				if(field_type == 'radio'){

					$.each(config_area,function(m,n){
						var is_selected = '';
						if(n['selected'] == 1){
							is_selected = ' checked ';
						}
						_html += '<input type="radio" name="'+name+'" value="'+n['id']+'" title="'+n['name']+'" '+is_selected+'>';
					});

				}else{

					$.each(config_area,function(m,n){
						var is_selected = '';
						if(n['selected'] == 1){
							is_selected = ' checked ';
						}
						_html += '<input type="checkbox" name="'+name+'[]" value="'+n['id']+'" lay-skin="primary" title="'+n['name']+'"  '+is_selected+'>';
					});

				}

				_html += '</div>';
				_this.append(_html);
				form.render();
				loading_num--;
				close_loading();
			}
		},"JSON");

	});

	$('.ajax_select_config').each(function(){
		var _this = $(this);
		var name = _this.attr('name');
		var field_type = _this.attr('field_type');
		var attr_type = _this.attr('attr_type');
		var val = _this.attr('val');

		$.post("{:url('Contentajax/ajax_select_config')}",{field_type:field_type,attr_type:attr_type,val:val},function(data){
			if(data.code != 1){
				layer.msg(data.msg,{icon:0});
				return false;
			}
			if(data.data){
				var _html = '';
				var data_class_id = name+'-';
				if(attr_type == 'config_area'){
					var config_area = data.data;

					$.each(config_area,function(m,n){
						if(n.length > 0){
							data_class_id += m+'-'
							_html += '<div class="layui-input-inline">';
							_html += '<select name="'+name+'-'+m+'" lay-filter="config_area" attr_class="'+data_class_id+'" attr_num="'+m+'" attr_name="'+name+'">';
							_html += '<option value="">--请选择--</option>';
							for(i = 0 ; i < n.length ; i++){
								var is_selected = '';
								if(n[i]['selected'] == 1){
									is_selected = ' selected ';
								}
								_html += '<option value="'+n[i]['id']+'" '+is_selected+'>'+n[i]['name']+'</option>';
							}
							_html += '</select>';
							_html += '</div>';
						}
					});
				}else{
					if(data.data.length == 0){
						return false;
					}
					var _html = '<div class="layui-input-inline">';
						_html += '<select name="'+name+'" lay-filter="'+attr_type+'" >';
						_html += '<option value="">--请选择--</option>';
					var config_area = data.data;
					$.each(config_area,function(m,n){
						var is_selected = '';
						if(n['selected'] == 1){
							is_selected = ' selected ';
						}
						_html += '<option value="'+n['id']+'" '+is_selected+'>'+n['name']+'</option>';
					});
					_html += '</select>';
					_html += '</div>';

				}

				_this.append(_html);
				form.render('select');
				loading_num--;
				close_loading();
			}else{
				_this.remove();
			}

		},"JSON");
	});

	form.on('select(config_area)', function(data){

		var attr_class = data.elem.getAttribute('attr_class');
		var attr_num = data.elem.getAttribute('attr_num');
		var attr_name = data.elem.getAttribute('attr_name');
		$(document).find("select[attr_class^='"+attr_class+"']").each(function(){
			console.log($(this))
			var _this_p_idv = $(this).attr("attr_class");
			if(_this_p_idv != attr_class){
			   $(this).parent().remove();
			}
		});
		$.post("{:url('Contentajax/ajax_config_area')}",{area_id:data.value},function(data){
			if(data.code != 1){
				layer.msg(data.msg,{icon:0});
				return false;
			}
			if(data.data.length == 0){
				return false;
			}
			attr_num++;
			data_class_id = name+'-';
			var _html = '<div class="layui-input-inline">';
				_html += '<select name="'+attr_name+'-'+attr_num+'" lay-filter="config_area" attr_class="'+attr_class+''+attr_num+'-" attr_num="'+attr_num+'" attr_name="'+attr_name+'">';
				_html += '<option value="">--请选择--</option>';
			var config_area = data.data;
			$.each(config_area,function(m,n){
				_html += '<option value="'+config_area[m]['id']+'" >'+config_area[m]['name']+'</option>';
			});
			_html += '</select>';
			_html += '</div>';

			$(".ajax_select_config[name='"+attr_name+"']").append(_html);
			form.render('select');
		},"JSON");
	});

});

</script>
</body>